/**
 * Created by fsj on 2017/6/6.
 */

export default  {
    /**
     * 获取url传过来的参数
     * @param name 参数名称
     * @param url URL地址
     * @param return
     */
    getQueryParam: function (name, url) {
        //URL GET 获取值
        var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i"),
            Url = url || location.href;
        if (reg.test(Url))
            return decodeURI(RegExp.$2.replace(/\+/g, " "));
        return "";

    },
    isApp: function() {
        if (window.qqlgclientwebview)
            return true;
        return false;
    },
    isIosApp: function() {
        if (window.qqlgioswebview)
            return true;
        return false;
    },
    isAndroidApp: function() {
        if (window.qqlgandroidwebview)
            return true;
        return false;
    },
    isWx: function (){
      if(navigator.userAgent.indexOf('MicroMessenger') > -1){
       return true;
      }
      return false;

      // var ua = navigator.userAgent.toLowerCase();
      //
      // if (ua.match(/MicroMessenger/i) == "micromessenger" || ua.match(/qq\//i) == "qq/") {
      //
      //   return true;
      //
      // } else {
      //
      //   return false;
      //
      // }

    },
    is_ios:function () {

    let ua = navigator.userAgent.toLowerCase();

    if (ua.match(/iphone/i) == "iphone" || ua.match(/ipad/i) == "ipad") {

      return true;

    }else {
      return false
    }

  }
};

/**
 * 存储localStorage
 */
export const setStore = (name, content) => {
    if (!name) return;
    if (typeof content !== 'string') {
        content = JSON.stringify(content);
    }
    window.localStorage.setItem(name, content);
};

/**
 * 获取localStorage
 */
export const getStore = name => {
    if (!name) return;
    return window.localStorage.getItem(name);
};

